"""
FIVEDASH(TM) -- General Purpose Accounting Software
Copyright (C) 2008  Obol Software Pty Ltd

This program is free software: you can redistribute it and/or modify
it. For terms and conditions, see fivedash/license/license.txt

"""

from phunc.logger import logger
from phunc.exception import GeneralBusinessErr

session_timeout = 1800
RESET_TIME_LIMIT = 1200 #reset session time limit

ROOT_PATH = ''
#COMPANY_LOGO_PATH = 'company/'
COMPANY_ROOT_PATH = '/var/fivedash/logos/'
COMPANY_VIRTUAL_PATH = '/company/'
JS_TEMP_PATH = '/var/fivedash/js_tmp/'
#sys_code code_id
BILLING_METHOD = 'billing_method'
CONTACT_TYPE = 'contact_type'
SMTP_SERVER = 'smtp_server'
SMTP_USER = 'smtp_user'
SMTP_PASS = 'smtp_pass'
THIS_EMAIL = 'this_email'
BUSINESS_NUM_LABEL = 'business_num_label'
ALT_LOCATION_TYPE = 'alt_location_type'
#billing method
BILLING_METHOD_ONE = 'hard copy'
BILLING_METHOD_TWO = 'email'
BILLING_METHOD_THREE = 'fax'
#billing method
#contact type
CONTACT_TYPE_EMAIL = 'email'
CONTACT_TYPE_FAX = 'fax'
CONTACT_TYPE_PHONE = 'phone'
CONTACT_TYPE_MOBILE = 'mobile'
CONTACT_TYPE_SMS = 'sms'
CONTACT_TYPE_POSITION = 'position'
#contact_type
#entity type
ENTITY_TYPE_PERSON = 'person'
ENTITY_TYPE_COMPANY = 'company'
ENTITY_TYPE_GOVERNMENT_DEPARTMENT = 'government department'
ENTITY_TYPE_NON_PROFIT_ORG = 'non-profit org'
#entity type
#alt location type
ALT_LOCATION_TYPE_COURIER_ADDRESS='courier_address'
ALT_LOCATION_TYPE_HOME='home'
ALT_LOCATION_TYPE_POSTAL_ADDRESS='postal address'
ALT_LOCATION_TYPE_WORK='work'
ALT_LOCATION_TYPE_OTHER='other'
#alt location type

#special account short name
ACCOUNTS_RECEIVABLE = 'ar'
ACCOUNTS_PAYABLE = 'ap'

ISO_COUNTRY_CODE_AUSTRALIA='AU'
BUSINESS_NUM_LABEL_AUSTRALIA = 'ABN'
BUSINESS_NUM_LABEL_OTHER = 'Business Number'


def getTemplateDir( req ):                
        template_dir = req.document_root()        
        template_dir = template_dir[:template_dir.rindex('skins')]+ 'templates/'        
        return template_dir
def getDocumentRootPath( req ):
        return req.document_root()

#--------------------------------------------------#
#       base information from form
#--------------------------------------------------#
query_string = '?1=1'
t = ''
v = ''
page = 0
page_string = ''
##a=''
##sl=''
##j=''

##def loadBaseInfo( form ):
##        global query_string
##        global t
##        global v
##        global page
##        global page_string
##        global a
##        global sl
##        global j
##        if form.has_key('j'):
##                j = form['j']
##        if form.has_key('sl'):
##                sl = form['sl']
##        if form.has_key('a'):
##                a = form['a']
##        if form.has_key('sys') and form['sys'] != 'bde':
##                sys = form['sys']
##                syslabel = 'BDE (' + sys.lower() + ')'
##                query_string = '?sys=' + sys
##                instance = sys
##        if form.has_key('t'):
##                t = form['t']
##        if form.has_key('v'):
##                v = form['v']
##        if form.has_key('page'):
##                page = int(form['page'])
##        else:
##                page = 1
##        page_string = ' LIMIT 20 OFFSET ' + str((page - 1) * 20)

#----------------------base info----------------
basic_save_path = "/var/fivedash/upload/crm"
INVOICE_FILE_PATH = 'invoice'

tp_index_path = "/usr/local/fivedash/cgi/phunc/tp_index"
tp_save_path = "/var/fivedash/upload/taxpage"
tp_server = "http://tps.obolsoftware.com/"
LOCAL_TP_INDEX_LOCK = tp_save_path + "/TPindex.py.lock"
LOCAL_TP_INDEX = tp_index_path + "/TPindex.py"
LOCAL_TP = tp_save_path + "/tp.ods"
TP_INDEX_ONLINE = tp_server + "TPindex.txt"
TP_INDEX_MD5_ONLINE = tp_server + "TPindex.txt.md5"

accounts_save_path = '/var/fivedash/upload/accounts'
ACCOUNTS_FILE = accounts_save_path + '/accounts.ods'


invalid_start_date ='19000101'
invalid_end_date = '21000101'
employee_code_prefix = 'employee_code_prefix'
salary_tax = 'salary_tax'

#----------------login info--------------------


main_menu = {'operations': ''' <div class="link-panel"><a href="/bin/operations.py">Operations</a></div> ''',
                        'crm':''' <div class="link-panel"><a href="/bin/crm.py">CRM</a></div> ''',
                        'finance':''' <div class="link-panel"><a href="/bin/finance.py">Finance</a></div> ''',
                        'admin':''' <div class="link-panel"><a href="/bin/admin.py">Admin</a></div> ''',
                        }

admin_menu = [''' <li><a href="/bin/appadmin/auc.py">Create New User</a></li> ''',
                        ''' <li><a href="/bin/appadmin/auu.py">Change Admin Password</a></li> ''',
                        ''' <li><a href="/bin/appadmin/acm.py">Company Management</a></li> ''',
                        ''' <li><a href="/bin/appadmin/get_right.py">Grant User rights</a></li> ''',
                        ''' <li><a href="/bin/appadmin/init_db.py">Create DB Script</a></li> ''',
                        ''' <li><a href="/bin/appadmin/right_tree.py">Display Company Organization</a></li> ''',
                        ]
                            
page_count = 20                
	
def _set_autocommit(connection): 
	"Make sure a connection is in autocommit mode." 
	if hasattr(connection, "autocommit"): 
		connection.autocommit(True) 
	elif hasattr(connection, "set_isolation_level"): 
		connection.set_isolation_level(0) 
